/****************/
/* Jiahui Shi	*/
/* 05/28/2011	*/
/* CS 244B	*/
/* Spring 2011	*/
/****************/
#ifndef CLIENT_H
#define CLIENT_H

#include "protocol.h"

enum {
  NormalReturn = 0,
  ErrorReturn = -1,
};

/* ------------------------------------------------------------------ */

#ifdef ASSERT_DEBUG
#define ASSERT(ASSERTION) \
 { assert(ASSERTION); }
#else
#define ASSERT(ASSERTION) \
{ }
#endif

/* ------------------------------------------------------------------ */

	/********************/
	/* Client Functions */
	/********************/
extern int InitReplFs( unsigned short portNum, int packetLoss );
extern int AddServer(char * id);
extern int OpenFile(char * strFileName);
extern int WriteBlock(int fd, char * strData, int byteOffset, int blockSize);
extern int Commit(int fd);
extern void Abort(int fd);
extern int CloseFile(int fd);

void* listenAddServerResponse(void * arg);
/* ------------------------------------------------------------------ */

uint32_t serverNum;
ServerType serverList[20];
uint8_t rece_response;
in_addr_t wait_server_ip;

uint32_t my_state;
#define INIT_STATE 0
#define WAIT_ADD_SERVER_RESPONSE 1
#define FLY_TAG 2
#define WAIT_TAG_RESPONSE 3


#define MAX_TRIALS 3 // max re-transmission trials
#define RETRIAL_TIME 300000 // in um
// #define TIME_OUT_THRESH 60 // in second
// #define HEARTBEAT 5 // in second
// #define MISSILE_SPEED 200 // in ms
float PACK_LOST_RATE;
Sockaddr groupAddr;
uint32_t my_socket;
Sockaddr myAddr;
in_addr_t myIP;

#endif


